﻿package Interface.Top100Classes
{
	import Interface.ArrowsScroller;
	
	import flash.events.MouseEvent;	
	
	public class TopScroller extends ArrowsScroller
	{
		private var FContainer:TopContainer;
		private var FPagesCount:int;
		private var FCurrentPage:int;
		
		public function TopScroller():void
		{
			super();
			
			FPagesCount = 0;
			FCurrentPage = 0;
			
			FContainer = getChildByName('Container') as TopContainer;			
			FUp.enabled = false;
			FDown.enabled = FContainer.PagesCount > 0;
		}
		
		public function Add(ALabel:TopLabel):void
		{
			FContainer.AddItem(ALabel);
			FDown.enabled = FContainer.PagesCount > 0;
		}
		
		public function Clear():void
		{
			FContainer.Clear();
			UpdateArrows();
		}
				
		override protected function OnUp(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveUp();
				UpdateArrows();
			}
		}
		
		override protected function OnDown(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveDown();
				UpdateArrows();
			}
		}
		
		public function UpdateArrows():void
		{
			FUp.enabled = !FContainer.IsFirstPage;
			FDown.enabled = !FContainer.IsLastPage;
		}
	}	
}
